﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class GameManager : MonoBehaviour {

    public GameObject hazard;
    public Vector3 spawnValues;

    public float waitTime;

	public Text scoreText;
	private int score = 0;

	// Use this for initialization
	void Start () {
		
        StartCoroutine("SpawnWaves");
	}
	
	// Update is called once per frame
	IEnumerator SpawnWaves () {
        yield return new WaitForSeconds(waitTime);
        while (true)
        {
            for (int i = 0; i < 10; i++)
            {
                Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
                Instantiate(hazard, spawnPosition, Quaternion.identity);
                yield return new WaitForSeconds(waitTime);

            }
            yield return new WaitForSeconds(10);
        }
        

        
	}

	public void AddScore(int value){
		score += value;
		updateScore ();
	}

	void updateScore(){
		scoreText.text = "Score:" + score;
	}

}
